package com.sw.study.mybatis.practie.test;

import com.sw.study.mybatis.practice.dynamicsql.DynameSqlUserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by sw on 2020/3/30.
 */
public class MybatisPractice {
    /**
     * 为了子类继承
     */
    public SqlSession sqlSession;
    @Before
    public void initEnv() throws IOException {
        InputStream inputStream= Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory= new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession=sqlSessionFactory.openSession();
    }


    @After
    public void after(){
        sqlSession.close();
    }

    /**
     *
     * @return
     */
    public DynameSqlUserMapper getDynameSqlUserMapper(){
        return sqlSession.getMapper(DynameSqlUserMapper.class);
    }



}